<template>
  <div>
    <van-nav-bar
      :title="(title as string)"
      left-arrow
      @click-left="onClickLeft"
      :border="false"
      :fixed="true"
      :placeholder="true"
      :safe-area-inset-top="true"
    >
      <template #left>
        <van-icon name="arrow-left" color="black" v-if="route.name != 'home'" size="20" />
      </template>
    </van-nav-bar>
  </div>
</template>
<script setup lang="ts">
import { ref, watchEffect } from "vue";
import { useRouter, useRoute } from "vue-router";
import { getInsureInfo } from "@/utils/api";
const router = useRouter();
const route = useRoute();

const title = ref("");
watchEffect(() => {
  if (route.query.type == "1") {
    title.value = "待支付订单";
  } else if (route.query.type == "2") {
    title.value = "我的保单";
  } else if (route.query.type == "4") {
    title.value = "已作废";
  } else if (route.query.type == "5") {
    getInsureInfo({ id: route.query.id }).then((res) => {
      title.value = res.msg.name;
    });
  } else {
    title.value = route.meta.title as string;
  }
});
// const getInfo = async () => {
//   const res = await getInsureInfo({ id: route.query.id });
//   return res.msg.name;
// };
const onClickLeft = () => {
  router.go(-1);
};
</script>
